#include "dsoundex.as"
	ds_init

	ds_load ".wav",0
	ds_load "qbg.wav",1
	ds_load "ACe.wav",2
	ds_load "_[W.wav",3
	ds_load "UUP.wav",4
	ds_load "{^.wav",5
	ds_load "NA[.wav",6

	randomize

*^Cgʏ
	buffer 2:picload "^Cg.bmp"

	gsel 0

*^Cg
	redraw 0

	pos 0,0:gmode:gcopy 2,0,0,640,480

	if _ŃJEg>=5:color:boxf 0,400,640,480

	_ŃJEg+:if _ŃJEg>=10:_ŃJEg=0

	getkey keyZ,90
	if keyZ=1:X^[g҂=5:ds_play 5:goto *Q[


	redraw 1
	await 30
	goto *^Cg

	

*Q[

	buffer 2:picload".bmp"
	buffer 3:picload"KubN.bmp"
	buffer 4:picload"jubN.bmp"
	buffer 5:picload"_ACe.bmp"
	buffer 6:picload"񕜃ACe.bmp"
	buffer 7:picload"U̓ACe.bmp"

	buffer 10:picload"S[.bmp"


	buffer 20:picload".bmp"
	buffer 21:picload"jGtFNg.bmp"
	buffer 22:picload"jGtFNg.bmp"

	




	ڌS=20
	B=5
	buffer 30:picload"Xe[W3.bmp":Xe[WTCY=ginfo(13):ڑ\=Xe[WTCY-ڌS



	dim IuWFNg,10,Xe[WTCY
	;IuWF= 0: 1:ubN 2:_ACe 3: 4:Uto 5:e 6:e 7:eE 8:e 9:~ 10:~ 11:~E 12:~ 13:ۃubN 14:XCb` 15:C{[ 16: 17: 18: 19: 50:S[
	dim ubNHP,10,Xe[WTCY
	MAXubNHP=4
	dim _,10,Xe[WTCY
	
	dim tO,10,Xe[WTCY
	dim ۑ傫,10,Xe[WTCY
	dim ֑傫,10,Xe[WTCY
	dim ,10,Xe[WTCY

	UUP=0

	repeat Xe[WTCY
		C=cnt
		repeat 10
			ubNHP(cnt,C)=-1
			_(cnt,C)=0
			pget cnt,C
			if (ginfo(16)=0)&(ginfo(17)=0)&(ginfo(18)=0):IuWFNg(cnt,C)=1;ubNo^
			if (ginfo(16)=0)&(ginfo(17)=0)&(ginfo(18)=255):IuWFNg(cnt,C)=2;_ACeo^
			if (ginfo(16)=0)&(ginfo(17)=255)&(ginfo(18)=0):IuWFNg(cnt,C)=3;񕜃ACeo^
			if (ginfo(16)=255)&(ginfo(17)=0)&(ginfo(18)=0):IuWFNg(cnt,C)=4;UUPACeo^

			if (ginfo(16)=255)&(ginfo(17)=0)&(ginfo(18)=255):IuWFNg(cnt,C)=15;UUPACeo^
			if (ginfo(16)=128)&(ginfo(17)=128)&(ginfo(18)=128):IuWFNg(cnt,C)=rnd(4)+16:ubNHP(cnt,C)=MAXubNHP;jubNo^
			
			if (ginfo(16)=0)&(ginfo(17)=255)&(ginfo(18)=255):IuWFNg(cnt,C)=50;S[o^
		loop
	loop

	e=30
	dim etO,e:dim eX,e:dim eY,e:dim eړ,e:dim ecړ,e:dim e,e
	eړ=18


	Ԍ=1
	X=4
	Y=13
	ԐU=0
	Ԉړ=6

	ԉړ=0
	cړ=0

	_=0
	MAXPHP=100
	PHP=MAXPHP

	U=0

	=0
	




	gsel 0


*MAIN
	redraw 0
	color:boxf

	repeat ڌS
		C=cnt+ڑ\
		if C>=Xe[WTCY:break
		repeat 10
			if C<Xe[WTCY-1:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)+cړ:gmode:gcopy 2,0,0,36,36;\

			if IuWFNg(cnt,C)=1:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-14+cړ:color 0,0,255:gmode 4,,,256:gcopy 3,0,0,36,50;ubN\
			if IuWFNg(cnt,C)=2:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-13+cړ:color 0,0,1:gmode 4,,,256:gcopy 5,0,0,36,46:gmode 5,,,ACe:gcopy 5,0,0,36,46;_ACe\
			if IuWFNg(cnt,C)=3:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-13+cړ:color 0,0,1:gmode 4,,,256:gcopy 6,0,0,36,46:gmode 5,,,ACe:gcopy 6,0,0,36,46;񕜃ACe\
			if IuWFNg(cnt,C)=4:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-13+cړ:color 0,0,1:gmode 4,,,256:gcopy 7,0,0,36,46:gmode 5,,,ACe:gcopy 7,0,0,36,46;UUPACe\

			if IuWFNg(cnt,C)=15:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-10+cړ:color 0,0,255:gmode 4,,,256:gcopy 4,C{[GX*36,0,36,46;jC{[ubN\
			if IuWFNg(cnt,C)=16:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-10+cړ:color 0,0,255:gmode 4,,,256:gcopy 4,36,0,36,46:if _(cnt,C)>0:_(cnt,C)-:if _ŃJEg=1:gcopy 4,0,0,36,46;jԃubN\
			if IuWFNg(cnt,C)=17:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-10+cړ:color 0,0,255:gmode 4,,,256:gcopy 4,72,0,36,46:if _(cnt,C)>0:_(cnt,C)-:if _ŃJEg=1:gcopy 4,0,0,36,46;j΃ubN\
			if IuWFNg(cnt,C)=18:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-10+cړ:color 0,0,255:gmode 4,,,256:gcopy 4,108,0,36,46:if _(cnt,C)>0:_(cnt,C)-:if _ŃJEg=1:gcopy 4,0,0,36,46;jubN\
			if IuWFNg(cnt,C)=19:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)-10+cړ:color 0,0,255:gmode 4,,,256:gcopy 4,144,0,36,46:if _(cnt,C)>0:_(cnt,C)-:if _ŃJEg=1:gcopy 4,0,0,36,46;jubN\

			if IuWFNg(cnt,C)=50:pos (cnt*36)+140,((C-ڑ\)*36)-(B*36)+cړ:gmode:gcopy 10,0,0,36,36;S[\

			if tO(cnt,C)=1:pos (cnt*36)+140+18,((C-ڑ\)*36)-(B*36)+cړ+18:color:gmode 4,36,36,(cnt,C):grotate 21,0,0,0.0,ۑ傫(cnt,C),ۑ傫(cnt,C):grotate 22,0,0,0.0,֑傫(cnt,C),֑傫(cnt,C):ۑ傫(cnt,C)+=7:֑傫(cnt,C)+=16:if ۑ傫(cnt,C)>=50:tO(cnt,C)=0
			
		loop
		if cnt=Y+~␳:pos (X*36)+140+ԉړ,((Y-B)*36)-21+ԐU:color 1,0,0:gmode 4,,,256:gcopy 20,Ԍ*36,0,36,57:if (_ŃJEg=1)&(UUP>0):gmode 5,,,256:gcopy 20,Ԍ*36,0,36,57;ԕ\
		if cnt=Y+~␳:pos (X*36)+140+ԉړ,((Y-B)*36)-21+ԐU:if (U>0)&(_ŃJEg=1):color 1,0,0:gmode 4,,,256:gcopy 20,144,0,36,57

		C=cnt
		repeat e
			if (etO.cnt!0)&(C=eY.cnt):pos (eX.cnt)*36+140+18+eړ.cnt,(eY.cnt-B)*36-10+cړ+18+ecړ.cnt:color:gmode 4,36,36,256:grotate 21,eF,0,0.0,(15-(25-e.cnt)/3)*U,(15-(25-e.cnt)/3)*U
		loop
		
	loop


	ACe+=50:if ACe>=256:ACe=0
	ԐU+:if ԐU>=3:ԐU=0

	C{[GX+:if C{[GX>=5:C{[GX=1



	getkey keyX,88
	getkey keyZ,90
	stick KEY,15
	if KEY&1:Ԍ=0:if (ԉړ=0)&(cړ=0):if keyX=0:if ((IuWFNg(X-1,Y+ڑ\)<=4)&(IuWFNg(X-1,Y+ڑ\)!1))|(IuWFNg(X-1,Y+ڑ\)=50):ԉړ-=Ԉړ
	if KEY&2:Ԍ=1:if (ԉړ=0)&(cړ=0):if keyX=0:if ((IuWFNg(X,Y+ڑ\-1)<=4)&(IuWFNg(X,Y+ڑ\-1)!1))|(IuWFNg(X,Y+ڑ\-1)=50):cړ+=Ԉړ
	if KEY&4:Ԍ=2:if (ԉړ=0)&(cړ=0):if keyX=0:if ((IuWFNg(X+1,Y+ڑ\)<=4)&(IuWFNg(X+1,Y+ڑ\)!1))|(IuWFNg(X+1,Y+ڑ\)=50):ԉړ+=Ԉړ
	if KEY&8:Ԍ=3:if (ԉړ=0)&(cړ=0):if keyX=0:if ((IuWFNg(X,Y+ڑ\+1)<=4)&(IuWFNg(X,Y+ڑ\+1)!1))|(IuWFNg(X,Y+ڑ\+1)=50):cړ-=Ԉړ:~␳=1

	if X^[g҂>0:keyZ=0:X^[g҂-

	if ԉړ<0:Ԍ=0:ԉړ-=Ԉړ:if ԉړ<=-36:ԉړ=0:X-
	if cړ>0:Ԍ=1:cړ+=Ԉړ:if cړ>=36:cړ=0:ڑ\-:gosub *W炷
	if ԉړ>0:Ԍ=2:ԉړ+=Ԉړ:if ԉړ>=36:ԉړ=0:X+
	if cړ<0:Ԍ=3:cړ-=Ԉړ:if cړ<=-36:cړ=0:ڑ\+:~␳=0:gosub *W₷

	gosub *e
		

	gosub *ACe

	gosub *ubNj󏈗

	U=1:eF=0
	if UUP>0:U=2:eF=36

	_ŃJEg+:if _ŃJEg>=2:_ŃJEg=0
	


	color 255,255,255:font"lr SVbN",12,1
	pos 30,40:mes "_:"+_+"P"
	pos 30,90:mes "HP:"+PHP+""
	color 255,0,0:boxf 30,105,100,110
	color 0,255,0:boxf 30,105,30+int((double(PHP)/double(MAXPHP))*70),110
	if UUP>0:color 255,0,0:pos 30,140:mes "U͂Q{!!"

	JIKAN=/10
	color 255,255,255:pos 30,200:mes"TIME:"+JIKAN+""

	pos 30,250:mes"c"+ڑ\+"C"


	pos 40,275:mes"GOAL"
	pos 36,395:mes"START"
	color 255,255,255:boxf 50,290,55,390;ʒu[^[
	;pos 53,290+int((double(ڑ\)/double(Xe[WTCY-ڌS))*100):gmode 2,36,36,256:grotate 21,0,0,0.0,13,13
	color 255,0,0:gmode 0,5,2,256:grect 53,290+int((double(ڑ\)/double(Xe[WTCY-ڌS))*100),0.0,6,4;ʒu[^[ʒu


	UUP-:if UUP<=0:UUP=0

	if U>0:pos rnd(6)-3,rnd(6)-3:gmode:gcopy 0,0,0,640,480
	U-:if U<=0:U=0

	+

	redraw 1
	if PHP<=0:goto *GAMEOVER
	if ڑ\=0:ds_play 6:goto *GAMECLEAR
	await 30
	goto *MAIN




*ACe
	if IuWFNg(X,Y+ڑ\)=2:IuWFNg(X,Y+ڑ\)=0:_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eY.cnt+ڑ\)<=0:ubNHP(eX.cnt,eY.cnt+ڑ\)=0
			if etO.cnt=3:eړ.cnt+=eړ:if eړ.cnt>36:eړ.cnt=0:eX.cnt+:if (IuWFNg(eX.cnt,eY.cnt+ڑ\)=1)|(IuWFNg(eX.cnt,eY.cnt+ڑ\)=15):etO.cnt=0:else:if IuWFNg(eX.cnt,eY.cnt+ڑ\)>=16:if IuWFNg(eX.cnt,eY.cnt+ڑ\)!50:etO.cnt=0:ubNHP(eX.cnt,eY.cnt+ڑ\)-=U:_(eX.cnt,eY.cnt+ڑ\)=10:ds_play 1:if ubNHP(eX.cnt,eY.cnt+ڑ\)<=0:ubNHP(eX.cnt,eY.cnt+ڑ\)=0
			if etO.cnt=4:ecړ.cnt+=eړ:if ecړ.cnt>36:ecړ.cnt=0:eY.cnt+:if (IuWFNg(eX.cnt,eY.cnt+ڑ\)=1)|(IuWFNg(eX.cnt,eY.cnt+ڑ\)=15):etO.cnt=0:else:if IuWFNg(eX.cnt,eY.cnt+ڑ\)>=16:if IuWFNg(eX.cnt,eY.cnt+ڑ\)!50:etO.cnt=0:ubNHP(eX.cnt,eY.cnt+ڑ\)-=U:_(eX.cnt,eY.cnt+ڑ\)=10:ds_play 1:if ubNHP(eX.cnt,eY.cnt+ڑ\)<=0:ubNHP(eX.cnt,eY.cnt+ڑ\)=0
		}
	loop
	

	return


*W炷
	repeat e
		if etO.cnt!0:eY.cnt+=1
	loop

	return


*W₷
	repeat e
		if etO.cnt!0:eY.cnt-=1
	loop

	return
		

*ubNj󏈗
	repeat ڌS
		C=cnt+ڑ\
		if C>=Xe[WTCY:break
		repeat 10
		if ubNHP(cnt,C)=0{
			ds_play 0
			tO(cnt,C)=1
			(cnt,C)=256
			ۑ傫(cnt,C)=10
			ubNHP(cnt,C)=-1
			=IuWFNg(cnt,C)
			IuWFNg(cnt,C)=0:_+=50
			if (IuWFNg(cnt-1,C)=)|(IuWFNg(cnt-1,C)=15):ubNHP(cnt-1,C)=-1000
			if (IuWFNg(cnt,C-1)=)|(IuWFNg(cnt,C-1)=15):ubNHP(cnt,C-1)=-1000
			if (IuWFNg(cnt+1,C)=)|(IuWFNg(cnt+1,C)=15):ubNHP(cnt+1,C)=-1000
			if (IuWFNg(cnt,C+1)=)|(IuWFNg(cnt,C+1)=15):ubNHP(cnt,C+1)=-1000

			if (cnt=X)&(Y=C-ڑ\+1):PHP-=10:U=10:ds_play 3
			if (cnt=X)&(Y=C-ڑ\-1):PHP-=10:U=10:ds_play 3
			if (cnt=X+1)&(Y=C-ڑ\):PHP-=10:U=10:ds_play 3
			if (cnt=X-1)&(Y=C-ڑ\):PHP-=10:U=10:ds_play 3
		}
		loop
	loop
	
	repeat ڌS
		C=cnt+ڑ\
		if C>=Xe[WTCY:break
		repeat 10
		if ubNHP(cnt,C)<=-1000{
			ubNHP(cnt,C)-
			if ubNHP(cnt,C)<=-1005:ubNHP(cnt,C)=0
		}
		loop
	loop

	


	return
	

*GAMEOVER
	buffer 2:pos 0,0:gmode:gcopy 0,0,0,640,480
	gsel 0

*GAMEOVERMAIN
	redraw 0
	pos 0,0:gmode:gcopy 2,0,0,640,480
	gmode 3,640,480,230:color:grect 320,240,0.0,640,480

	color 255,255,255:font"lr SVbN",30,1
	pos 250-2,100:mes"GAME OVER":pos 250+2,100:mes"GAME OVER":pos 250,100-2:mes"GAME OVER":pos 250,100+2:mes"GAME OVER"
	color 255,0,0:pos 250,100:mes"GAME OVER"

	color 255,255,255:pos 300,200:mes ""+_+"P"
	color 255,255,255:pos 150,330:mes "Xy[XL[F^Cg"

	stick KEY
	if KEY&16:ds_play 5:goto *^Cgʏ

	redraw 1
	await 30
	goto *GAMEOVERMAIN



*GAMECLEAR
	buffer 2:pos 0,0:gmode:gcopy 0,0,0,640,480
	gsel 0

	{[iX_=25300-(JIKAN*4)
	ŏI_=_+{[iX_

*GAMECLEARMAIN
	redraw 0
	pos 0,0:gmode:gcopy 2,0,0,640,480
	gmode 3,640,480,230:color:grect 320,240,0.0,640,480

	color 255,255,255:font"lr SVbN",30,1
	pos 240-2,100:mes"GAME CLEAR":pos 240+2,100:mes"GAME CLEAR":pos 240,100-2:mes"GAME CLEAR":pos 240,100+2:mes"GAME CLEAR"
	color 0,200,0:pos 240,100:mes"GAME CLEAR"

	font"lr SVbN",20,1
	color 255,255,255:pos 270,170:mes "_F"+_+"P"
	color 255,255,255:pos 240,200:mes "ԓ_F"+{[iX_+"P"

	font"lr SVbN",30,1
	color 100,100,255:pos 170,250:mes "ŏI_F"+ŏI_+"P"
	color 255,255,255:pos 150,330:mes "Xy[XL[F^Cg"

	stick KEY
	if KEY&16:ds_play 5:goto *^Cgʏ

	redraw 1
	await 30
	goto *GAMECLEARMAIN
	